package com.stores.v1.model;

import com.stores.v1.entity.*;
import com.stores.v1.toolset.*;

public class SiteManagerModel extends PersonModel {

	/***
	 * 
	 * @param userContext
	 */
	public SiteManagerModel(SiteManager userContext) {
		super.setUserContext(userContext);
	}

	@Override
	public void setUserContext(Person userContext) {
	}

	@Override
	public int createUser(Person user) throws DatabaseInitializationException,
			DatabaseTransactionException, AccessControlException,
			DatabaseCommandException {
		int userId = 0;
		int securityGroupId = this.getGroupIdByPerson(user);
		boolean isAllowed = this.isAllowed();
		if (isAllowed) {
			userId = this.createPerson(user, securityGroupId);
		} else {
			throw new AccessControlException(String.format(
					"User [%d] cannot create [%s]", this.getUserContext()
							.getId(), user.getClass().getName()));
		}
		return userId;
	}	
}
